package com.txy.test.domain.strategy.service.raffle;


import com.txy.domain.strategy.service.IRaffleService;
import com.txy.domain.strategy.model.entity.RaffleFactorEntity;
import com.txy.domain.strategy.service.armory.IStrategyArmory;
import com.txy.domain.strategy.service.rule.chain.impl.RuleWeightLogicChain;
import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.util.ReflectionTestUtils;

import javax.annotation.Resource;

@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class DefaultRaffleChainServiceTest {
    @Resource
    private IRaffleService defaultRaffleService;

    @Resource
    private IStrategyArmory strategyArmory;

    @Resource
    private RuleWeightLogicChain ruleWeightLogicChain;

    @Before
    public void setUp() {
        strategyArmory.assembleLotteryStrategy(100001L);
        strategyArmory.assembleLotteryStrategy(100002L);
        strategyArmory.assembleLotteryStrategy(100003L);

        ReflectionTestUtils.setField(ruleWeightLogicChain, "userScore", 4500L);
    }

    @Test
    public void test_ruleBlackList() {
        defaultRaffleService.performRaffle(RaffleFactorEntity.builder()
                .userId("user001")
                .strategyId(100001L).build());
    }

    @Test
    public void test_ruleWeight() {
        defaultRaffleService.performRaffle(RaffleFactorEntity.builder()
                .userId("txy")
                .strategyId(100001L).build());
    }

    @Test
    public void test_default() {
        ReflectionTestUtils.setField(ruleWeightLogicChain, "userScore", 0L);
        defaultRaffleService.performRaffle(RaffleFactorEntity.builder()
                .userId("txy")
                .strategyId(100001L).build());
    }
}
